from Base import Base
import pytest,yaml

class Test_a3mall():
    token = None
    @pytest.fixture(scope="session")
    def api(self):
        return Base()

    def test_post_login(self,api):
        login_data = {"username":"18620064667","password":"123456"}

        login = api.post(
            path="/api/public/login",
            json=login_data
        )
        print(login.json())
        Test_a3mall.token = 'Bearer ' + login.json()['data']['token']
        assert 200 == login.status_code

    def test_second(self,api):
        tou = {'auth-token':Test_a3mall.token}
        info = api.get(
            path = '/api/second?page=1&type=0&sort=1',
            headers=tou
        )
        print(info.json())

    def test_view(self, api):
        tou = {'auth-token': Test_a3mall.token}
        view = api.get(
            path='/api/second/view?id=6',
            headers=tou
        )
        print(view.json())

    def test_shopping(self,api):
        tou = {'auth-token':Test_a3mall.token}
        shopping = api.get(
            path='/api/order/confirm?id=6&type=second&sku_id=&num=1&shipping_type=1',
            headers=tou
        )
        print(shopping.json())

    def test_create(self,api):
        tou = {'auth-token':Test_a3mall.token}
        body = {
            'address_id':'106',
            'bonus_id':'0',
            'id':'6',
            'num':'1',
            'payment':'balance',
            'remarks':'',
            'shipping_type':'1',
            'sku_id':'',
            'source':'1',
            'store_id':'1',
            'type':'second'
            }
        create = api.post(
            path='/api/order/create',
            json=body,
            headers=tou
        )
        print(create.json())

if __name__ == '__main__':
    pytest.main(["-s"])